<template>
  <div>
    <el-table :data="tableData">
      <el-table-colum type="index" width="50" label="序号"></el-table-colum>
      <el-table-column label="专业名称" prop="academy"></el-table-column>
      <el-table-column
        label="认证专业类"
        prop="certProfessionType"
      ></el-table-column>
      <el-table-column label="归属院系" prop="certProfession"></el-table-column>
      <el-table-column label="专业负责人" prop="certCharge"></el-table-column>
      <el-table-column label="认证文件"  prop="certAttachmentId">
        <template slot-scope="scope">
          <el-button type="text" @click="preview(scope.row.certAttachmentId)">查看文件</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row type="flex" justify="center" style="margin-top:20px">
      <el-col :span="4">
        <el-button type="primary" @click="isPass(1)">通 过</el-button>
        <el-button type="primary" @click="isPass(2)">驳 回</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
let Base64 = require('js-base64').Base64
export default {
  data() {
    return {
      dialogVisible: false,
      tableData: [
        {
          majorName: "物理学",
          choose: "本科",
          kinds: "中学教育类",
          college: "物理与电子工程学院",
          people: "张XX",
          doc: "物理师范认证文件"
        }
      ],
      page: {
        pageNum: 1,
        pageSize: 10
      },
      remark: ""
    };
  },
  created() {
    this.getCert();
  },
  computed: {
    getId() {
      return this.$route.query.id;
    }
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    getCert() {
      this.$http({
        url: this.$http.reviewed(`/admin/certDetailPage/${this.getId}`),
        method: "get",
        params: this.$http.adornParams(
          {
            ...this.page
          },
          false
        )
      }).then(res => {
        this.tableData = res.data.data.records;
      });
    },

    isPass(val) {
      if (val === 1) {
        this.$http({
          url: this.$http.reviewed("/admin/cert/"),
          method: "put",
          params: this.$http.adornParams(
            {
              certId: this.getId,
              status: val
            },
            false
          )
        }).then(res => {
          this.$message({
            type: "success",
            message: "通过成功"
          });
          this.$router.go(-1);
        });
      } else {
        this.$prompt("请输入驳回理由", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消"
        })
          .then(({ value }) => {
            this.$http({
              url: this.$http.reviewed("/admin/cert/"),
              method: "put",
              params: this.$http.adornParams(
                {
                  certId: this.getId,
                  status: val,
                  remark: value
                },
                false
              )
            }).then(res => {
              this.$message({
                type: "success",
                message: "驳回成功"
              });
              this.$router.go(-1);
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入"
            });
          });
      }
    },
     preview(id) {
       console.log(id);
      this.$http({
          url:this.$http.fileUpload(`/file/admin/info/${id}`),
          method: "get"
        }).then(res => {
          window.open('https://file.keking.cn/onlinePreview?url='+encodeURIComponent(Base64.encode(res.data.data.path)))
        })
    }
  }
};
</script>

<style></style>
